<?php
/**
 * Created by PhpStorm.
 * User: Sky
 * Date: 16/1/22
 * Time: 下午2:21
 */

use yii\helpers\Url;

$web = Url::to("@web");

?>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <title>收礼记录列表</title>
    <link type="text/css" href="<?= $web ?>/css/bag/global.css" rel="stylesheet"/>
    <link type="text/css" href="<?= $web ?>/css/home/receive-record.css" rel="stylesheet"/>
    <script type="text/javascript" src="<?= $web ?>/js/jquery.js"></script>
    <script type="text/javascript" src="<?= $web ?>/js/tools.js"></script>
    <script type="text/javascript" src="<?= $web ?>/js/home/receive-record.js"></script>

    <link type="text/css" href="<?= $web ?>/css/datepicker.css" rel="stylesheet"/>
    <script type="text/javascript" src="<?= $web ?>/js/datepicker.js"></script>

    <script type="application/javascript">
        $(document).ready(function () {
            var w = $(document).width();
            if (w > 640) {
                w = 640;
            }
            $("body").css("font-size", w * 20 / 320);
        });

        var start = 0;
        var pagesize = 8;
        var receive_record="";

        var status='';
        var type='';
        //当前时间前推一个月
        var tmp=new Date((new Date()).getTime()-31 * 24 * 3600 * 1000);
        var begintime=timestampToDatetime_ymd(tmp);
        var endtime=timestampToDatetime_ymd(new Date());
        $(function ($) {
            receive_record = returnstring("<?=$web?>/js/home/receive_record.tpl");
            loadRList(true);
        });

        $(window).scroll(function () {
            var scrollTop = $(this).scrollTop();
            var scrollHeight = $(document).height();
            var windowHeight = $(this).height();
            if (scrollTop + windowHeight == scrollHeight) {
                isScroll=true;
                loadRList(false);
//                alert(1);
            }
        });



        function loadRList(isClear) {
            if (isClear){
                start = 0;
            }
            var data = {};
            data.start = start;
            data.pagesize = pagesize;
            data.status = status;

            data.type = type;
            data.begintime = begintime;
            data.endtime = endtime;

            var re = returnjson("<?=Url::to(['wx-home/get-receive-record-handle'])?>", data);
            if (re.flag == 0) {
                alert(re.msg);
                return;
            } else {
                var target = $(".main ul");
                if (isClear){
                    target.empty();
                }

                $.each(re.rlist, function (i, item) {
                    var dom = document.createElement("li");
                    dom.innerHTML = receive_record._format({
                        web:'<?=$web?>',
                        NAME: item.NAME || "来自{name}的朵拉礼包"._format({name:item.NICK_NAME}) ,
                        PRICE: item.PRICE,
                        NUM:item.NUM,
                        CREATE_DATETIME_SHOW:item.CREATE_DATETIME_SHOW,
                        iconflag:item.TYPE=='card'?'1':'2',
                        status:calc_status(item.TYPE,item.STATUS)?"已兑换":"未兑换",
                        status_css:calc_status(item.TYPE,item.STATUS)?'paied-label':'unpaied-label',
                        valid_date_message:item.VALID_DATE_MESSAGE,
                        code_id:item.CODE_ID,
                        type:item.TYPE
                    });
                    target.get(0).appendChild(dom);
                });
                start = start + re.rlist.length;

            }

        }
        function calc_status(type,status){
            if(type=='bag'){
                if(status=='1'){
                    return false;
                }
                if(status=='2' || status=='3'){
                    return true;
                }

            }
            if(type=='card'){
                if(status=='1'){
                    return false;
                }
                if(status=='2' || status=='5'){
                    return true;
                }

            }
        }
        function swichType(ttype){
            type=ttype;
            loadRList(true);
        }
        $(function($){
            $(".header .filter").click(function () {
                //回显
                //status
                $('.filter-frame .filter-item').removeClass('filter-item-selected');
                $('.filter-frame .filter-item').siblings('[v="'+status+'"]').addClass('filter-item-selected');
                //time
                $("#v_begintime").html(begintime);
                $("#v_endtime").html(endtime);
                $(".dialog-frame").show();
            });
        });

        function findexec(){
            var v= $('.filter-frame .filter-item-selected').attr('v');
            status=v;
            begintime=$("#v_begintime").html();
            endtime=$("#v_endtime").html();
            loadRList(true);
            $(".dialog-frame").hide();
        }

        function href_detail(type,code_id){
            code_id = encodeURI(code_id);
            if(type=='bag'){
                window.location.href = "<?=Url::to(["wx-bag/view-gift-nav"]);?>?code_id=" + code_id;
            }
            if(type=='card'){
                window.location.href = "<?=Url::to(["wx-biz/view-gift-nav"]);?>?code_id=" + code_id;
            }
        }
    </script>
</head>
<body>
<div class="main">
    <div class="tab-frame">
        <div class="tab-item" onclick="swichType('')"><label class="selected">全部记录</label></div>
        <div class="tab-item" onclick="swichType('card')"><label>朵拉礼卡</label></div>
        <div class="tab-item" onclick="swichType('bag')"><label>朵拉礼包</label></div>
    </div>
    <div class="header">
        <div class="txt"><label>我的收礼记录(一个月内)</label></div>
        <div class="filter"><img src="<?= $web ?>/img/home/receive-record/filter.png"></div>
    </div>
    <ul>

    </ul>

    <div class="dialog-frame">
        <div class="mask"></div>
        <div class="dialog-content">
            <a class="btn-close" style="background-image: url('<?= $web ?>/img/home/send-record/btn-close.png')"></a>
            <div class="content-frame">
                <div class="filter-frame">
                    <a class="filter-item filter-item-selected" v=""><label>全部</label></a>
                    <a class="filter-item" style="margin-left: 0.1em;" v="2"><label>已兑换</label></a>
                    <a class="filter-item" style="margin-left: 0.1em;" v="1"><label>未兑换</label></a>
                </div>
                <div class="date-frame" style="top: 5em;">
                    <div class="date-txt"><label>起始日期:</label><label data-toggle="datepicker" id="v_begintime">2016-01-23</label></div>
                    <div class="date-icon"><img src="<?= $web ?>/img/home/receive-record/icon-startdate.png"></div>
                </div>
                <div class="date-frame" style="top: 8em;">
                    <div class="date-txt"><label>结束日期:</label><label data-toggle="datepicker" id="v_endtime">2016-01-23</label></div>
                    <div class="date-icon"><img src="<?= $web ?>/img/home/receive-record/icon-enddate.png"></div>
                </div>
                <a class="btn-ok" onclick="findexec();">
                    <label>立即查询</label>
                </a>
            </div>
        </div>
    </div>
</div>
</body>

</html>
